﻿package com.tudou.home.newskin.containers
{
    import com.tudou.home.common.utils.*;
    import com.tudou.home.consts.*;
    import com.tudou.home.newskin.consts.*;
    import com.tudou.home.newskin.model.*;
    import com.tudou.skin.*;
    import com.tudou.utils.*;
    import flash.display.*;

    public class PlayFinishedSprite extends Sprite implements ITransform, IShare, IInitVideo, IRelativeVideo, IFullscreen, IExpand, IPlayComplete, ITransFinished
    {
        private var shareSprite:ShareSprite;
        private var isFullscreen:Boolean = false;
        private var nextItemSprite:NextItemSprite;
        private var relative:RelativeVideoSprite;
        private var goWidth:uint = 400;
        private var isExpand:Boolean = false;
        private var finishTitleSprite:FinishTitleSprite;
        private var background:DisplayObject;
        private var goHeight:uint = 300;
        private var line:DisplayObject;
        private var _showTransFinished:Boolean = false;

        public function PlayFinishedSprite()
        {
            background = RectDisplayUtil.getShape(100, 75, 0, 1);
            addChild(background);
            line = new PlayCompleteLineMC();
            addChild(line);
            finishTitleSprite = new FinishTitleSprite();
            addChild(finishTitleSprite);
            shareSprite = new ShareSprite();
            addChild(shareSprite);
            shareSprite.visible = false;
            nextItemSprite = new NextItemSprite();
            addChild(nextItemSprite);
            nextItemSprite.visible = false;
            relative = new RelativeVideoSprite();
            addChild(relative);
            return;
        }// end function

        public function set showTransFinished(param1:Boolean) : void
        {
            _showTransFinished = param1;
            relative.showTransFinished = param1;
            finishTitleSprite.showTransFinished = param1;
            if (param1)
            {
                shareSprite.visible = false;
                nextItemSprite.visible = true;
                finishTitleSprite.visible = true;
            }
            else
            {
                nextItemSprite.visible = false;
                finishTitleSprite.visible = false;
                shareSprite.visible = true;
            }
            goTransform(goWidth, goHeight, isFullscreen);
            return;
        }// end function

        public function goTransform(param1:uint, param2:uint, param3:Boolean) : void
        {
            var _loc_4:Number = NaN;
            var _loc_5:Number = NaN;
            goWidth = param1;
            goHeight = param2;
            this.isFullscreen = param3;
            if (!param3 && PlayerConsts.FIXED_MAIN_WIDTH > param1)
            {
                param1 = PlayerConsts.FIXED_MAIN_WIDTH;
                param2 = PlayerConsts.FIXED_MAIN_HEIGHT;
            }
            background.width = param1;
            background.height = param2;
            if (param3)
            {
                relative.setRelativeAreaPerPage(param1 <= 800 ? (5) : (6), 2);
                _loc_4 = NewSkinConsts.RELATIVE_XBETWEEN_FULLSCREEN;
                _loc_5 = NewSkinConsts.RELATIVE_YBETWEEN_FULLSCREEN;
            }
            else if (isExpand)
            {
                if (_showTransFinished)
                {
                    relative.setRelativeAreaPerPage(param1 <= 800 ? (5) : (6), 1);
                }
                else
                {
                    relative.setRelativeAreaPerPage(param1 <= 800 ? (5) : (6), 2);
                }
                _loc_4 = NewSkinConsts.RELATIVE_XBETWEEN_FULLSCREEN;
                _loc_5 = NewSkinConsts.RELATIVE_YBETWEEN_FULLSCREEN;
            }
            else
            {
                relative.setRelativeAreaPerPage(4, 1);
                _loc_4 = NewSkinConsts.RELATIVE_XBETWEEN_NORMAL;
                _loc_5 = NewSkinConsts.RELATIVE_YBETWEEN_NORMAL;
            }
            relative.setXYBetween(_loc_4, _loc_5);
            relative.goTransform(param1, param2, param3);
            LayoutUtil.middle(relative, true, param1);
            LayoutUtil.middle(line, true, param1);
            LayoutUtil.middle(shareSprite, true, param1);
            LayoutUtil.middle(nextItemSprite, true, param1);
            LayoutUtil.middle(finishTitleSprite, true, param1);
            var _loc_6:Number = 60;
            var _loc_7:Number = 30;
            var _loc_8:* = shareSprite.height + _loc_6 + relative.height;
            if (_showTransFinished)
            {
                _loc_6 = 40;
                _loc_7 = 20;
                _loc_8 = finishTitleSprite.height + nextItemSprite.height + _loc_6 + relative.height;
            }
            var _loc_9:* = int((param2 - _loc_8) / 2);
            if (_showTransFinished)
            {
                finishTitleSprite.y = _loc_9;
                _loc_9 = int(finishTitleSprite.y + finishTitleSprite.height);
                nextItemSprite.y = _loc_9;
                _loc_9 = nextItemSprite.y + nextItemSprite.height + _loc_7;
            }
            else
            {
                shareSprite.y = _loc_9;
                _loc_9 = shareSprite.y + shareSprite.height + _loc_7;
            }
            line.y = _loc_9;
            relative.y = int(line.y + (_loc_6 - _loc_7));
            var _loc_10:Number = 1;
            if (!param3 && PlayerConsts.FIXED_MAIN_WIDTH > goWidth)
            {
                _loc_10 = goWidth / PlayerConsts.FIXED_MAIN_WIDTH;
            }
            var _loc_11:* = _loc_10;
            this.scaleY = _loc_10;
            this.scaleX = _loc_11;
            return;
        }// end function

        public function setShareItemList(param1:Array) : void
        {
            shareSprite.setShareItemList(param1);
            return;
        }// end function

        public function setPlaylistSingleContinue(param1:Boolean) : void
        {
            finishTitleSprite.setPlaylistSingleContinue(param1);
            return;
        }// end function

        public function setRelativeList(param1:Array) : void
        {
            relative.setRelativeList(param1);
            nextItemSprite.setRelativeList(param1);
            return;
        }// end function

        public function startTransFinishTimeout() : void
        {
            finishTitleSprite.startTransFinishTimeout();
            return;
        }// end function

        public function showComplete() : void
        {
            finishTitleSprite.showComplete();
            return;
        }// end function

        public function hideComplete() : void
        {
            finishTitleSprite.hideComplete();
            return;
        }// end function

        public function setExpand(param1:Boolean) : void
        {
            isExpand = param1;
            goTransform(goWidth, goHeight, isFullscreen);
            return;
        }// end function

        public function setBaseVideoInfo(param1:IBaseVideoInfo) : void
        {
            shareSprite.setBaseVideoInfo(param1);
            nextItemSprite.setBaseVideoInfo(param1);
            return;
        }// end function

        public function stopTransFinishTimeout() : void
        {
            finishTitleSprite.stopTransFinishTimeout();
            return;
        }// end function

        public function exitFullscreen() : void
        {
            isFullscreen = false;
            return;
        }// end function

        public function enterFullscreen() : void
        {
            isFullscreen = true;
            return;
        }// end function

    }
}
